package com.imooc.girl.service;

import com.imooc.girl.domain.Girl;
import com.imooc.girl.exception.GirlException;
import com.imooc.girl.repository.GirlRepository;
import com.imooc.girl.result.ResultEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: 业务逻辑层
 * @program: girl
 * @author: Administrator
 * @date: 2019/2/19 16:02
 */
@Service
public class GirlService {

    @Autowired
    private GirlRepository repository;

    public void getAge(Integer id) throws GirlException {
        Girl girl = repository.findOne(id);
        int age = girl.getAge();
        if (age < 10) {
            // code = 100
            throw new GirlException(ResultEnums.PRIMARY_SCHOOL);
        } else if (age < 16) {
            // code = 101
            throw new GirlException(ResultEnums.MIDDLE_SCHOOL);
        }
    }

    public Girl findOne(Integer id) {
        Girl girl = repository.findOne(id);
        return girl;
    }
}
